﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LTJ.Common;
using LTJ.Data;
using LTJ.FrameWork;
using System.Data;
using LTJ.Entity;

namespace uswinweb.user
{
    public partial class price_update : UserPage
    {
        public DataTable netpricespecsTab = new DataTable(); //海运净价
        public DataTable usdfeeTab = new DataTable();//美金费用
        public DataTable rmbfeeTab = new DataTable();//人民币费用
        public string DateBegin;
        public string DateEnd;

        public int rid = SASRequest.GetInt("rid", 0);
        public RouteBaseInfo rbInfo = new RouteBaseInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            netpricespecsTab = BaseDatas.GetBaseDataListByStr(" code='netpricespecs' ");
            usdfeeTab = BaseDatas.GetBaseDataListByStr(" code='usdfee' ");
            rmbfeeTab = BaseDatas.GetBaseDataListByStr(" code='rmbfee' ");
            DateBegin = DateTime.Now.ToShortDateString();
            DateEnd = DateTime.Now.AddDays(-7).ToShortDateString();
            rbInfo = RouteBases.GetRouteBaseInfo(rid);
            if (SASRequest.IsPost())
            {
                updateroutebase();
            }
        }
        protected void updateroutebase()
        {
            string lodeport = SASRequest.GetFormString("shipPort_hidd_luffy");//起运港code
            string destport = SASRequest.GetFormString("purposePort_hidd_luffy");//目的港code
            string tranport = SASRequest.GetFormString("transitPort_hidd_luffy");//中转港code
            string bcode = SASRequest.GetFormString("shipcomp_hidd_luffy");//船公司code
            string pier = SASRequest.GetFormString("terminal_hidd_luffy");//码头code
            string schbegin = SASRequest.GetFormString("schedule1_hidd_luffy");//开始船期
            string schend = SASRequest.GetFormString("schedule2_hidd_luffy");//结束船期
            string range = SASRequest.GetFormString("voyagetxt");//航程
            string validbegin = SASRequest.GetFormString("begindate");//有效期起始
            string validend = SASRequest.GetFormString("enddate");//有效期截止
            string bio = SASRequest.GetFormString("beizhu");//备注
            int cid = userinfo.cid;
            int uid = userid;
            string fees = "";
            //读取海运净价
            foreach (System.Data.DataRow dr in netpricespecsTab.Rows)
            {
                fees += "'netpricespecs','" + dr["tcode"].ToString().Trim() + "','" + dr["tcode"].ToString().Trim() + "','" + SASRequest.GetString("vip_" + dr["tcode"].ToString().Trim() + "_txt") + "','" + SASRequest.GetString("reg_" + dr["tcode"].ToString().Trim() + "_txt") + "','" + SASRequest.GetString("foreign_" + dr["tcode"].ToString().Trim() + "_txt") + "'|";
            }
            //读取美金费用
            foreach (System.Data.DataRow dr in usdfeeTab.Rows)
            {
                foreach (System.Data.DataRow drr in netpricespecsTab.Rows)
                {
                    fees += "'usdfee','" + dr["tcode"].ToString().Trim() + "','" + drr["tcode"].ToString().Trim() + "','" + SASRequest.GetString("usdfee_" + drr["tcode"].ToString().Trim() + "_" + dr["tcode"].ToString().Trim() + "_txt") + "','0','0'|";
                }
            }
            //读取人民币费用

            foreach (System.Data.DataRow dr in rmbfeeTab.Rows)
            {
                foreach (System.Data.DataRow drr in netpricespecsTab.Rows)
                {
                    fees += "'rmbfee','" + dr["tcode"].ToString().Trim() + "','" + drr["tcode"].ToString().Trim() + "','" + SASRequest.GetString("rmbfee_" + drr["tcode"].ToString().Trim() + "_" + dr["tcode"].ToString().Trim() + "_txt") + "','0','0'|";
                }
            }
            rbInfo.loadport = lodeport;
            rbInfo.destport = destport;
            rbInfo.tranport = tranport;
            rbInfo.bcode = bcode;
            rbInfo.pier = pier;
            rbInfo.schbegin = schbegin;
            rbInfo.schend = schend;
            rbInfo.range = range;
            rbInfo.validbegin = validbegin;
            rbInfo.validend = validend;
            rbInfo.bio = bio;
            rbInfo.cid = cid;
            rbInfo.uid = uid;
            rbInfo.fees = fees.Trim('|');
            int msg = RouteBases.UpdateRouteBase(rbInfo);
            if (msg > 0)
            {
                base.RegisterStartupScript("PAGE", "parent.document.getElementById('reclick').click();parent.Lightview.hide();");
            }
        }
        public string GetName(string type, string pcode)
        {
            string msg = "&nbsp;";
            string strWhere = " code='" + type.Trim() + "' and tcode='" + pcode.Trim() + "' ";
            BaseDataInfo binfo = BaseDatas.GetBaseDataByStr(strWhere);
            if (binfo != null)
            {
                if (type == "dock")
                {
                    msg = binfo.tcode;
                }
                else
                {
                    msg = binfo.ename;
                }
            }
            return msg;
        }

    }
}